import React from 'react';
import { Menu } from 'antd';
import Icon from '../icon';

const Nav = (props: any) => {
  const { routes, history } = props;
  const { location } = history;
  const handleClick = (value: any) => {
    history.push(value.key);
  };
  return (
    <Menu onClick={handleClick} selectedKeys={[location.pathname]} mode="horizontal">
      {routes && routes.length > 0
        ? routes.map((item: any, index: number) => {
          return (
            item.header ? (
              <Menu.Item
                key={item.path}
                icon={index === 0 ? <Icon type="icon-zhibo" /> : <Icon type="icon-zhanghuzhongxin" />}
              >
                {item.name}
              </Menu.Item>
            ) : null
          );
        })
        : null}
    </Menu>
  );
};
export default Nav;
